<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{$caption}</title>
    <link rel="stylesheet" href="__PUBLIC__/User/css/weui.css"/>
    <link rel="stylesheet" href="__PUBLIC__/User/css/example.css"/>
    <link rel="stylesheet" href="__PUBLIC__/User/pc/css/bootstrap.min.css">
    <link rel="stylesheet" href="__PUBLIC__/User/css/swiper.min.css">
    <link rel="stylesheet" href="__PUBLIC__/User/css/ion.calendar.css">
    <link rel="stylesheet" href="__PUBLIC__/User/css/mystyle.css"/>
    <link rel="stylesheet" href="__PUBLIC__/User/css/zTreeStyle.css">
    <link rel="stylesheet" href="__PUBLIC__/User/css/treeDemo.css" type="text/css">
    <!--文件上传-->
    <link rel="stylesheet" href="__PUBLIC__/User/css/jquery.filer.css">
    <link rel="stylesheet" href="__PUBLIC__/User/css/jquery.filer-dragdropbox-theme.css">
    <link rel="stylesheet" href="__PUBLIC__/User/css/custom.css">

    <script src="__PUBLIC__/User/newjs/jquery.js"></script>
    <script src="__PUBLIC__/User/js/swiper.min.js"></script>
    <script src="<?php echo $dic;?>"></script>
    <script src="<?php echo $layer;?>"></script>
    <script src="__PUBLIC__/User/newjs/moment.min.js"></script>
    <script src="__PUBLIC__/User/newjs/moment.zh-cn.js"></script>
    <script src="__PUBLIC__/User/newjs/pc_dom_tool_final.js"></script>
    <script src="__PUBLIC__/User/js/layer.js"></script>
    <script src="__PUBLIC__/User/newjs/jquery.ztree.core.js"></script>
    <script src="__PUBLIC__/User/newjs/myztree.js"></script>
    <!--文件上传插件-->
    <script src="__PUBLIC__/User/newjs/jquery.filer.min.js" type="text/javascript"></script>
    <!-- 二次定义weui样式开始 -->
    <style>
        .swiper-container{
            overflow: visible !important;
        }
        .swiper-pagination{
            position: relative !important;
            top:6px !important;
            z-index: 999 !important
        }
        .swiper-pagination-bullet{
            margin-top:5px !important;
            width:20px;
            height:20px;
            text-align:center;
            line-height:20px;
            font-size:12px;
            color:#000;
            opacity:1;
            background:rgba(0,0,0,0.2);
        }
        .swiper-pagination-bullet-active{
            color:#fff;
            background:#007aff;
        }
    </style>
    <!-- 二次定义weui样式结束 -->
    <script>
        var sj_info = eval({$sj_info}); //时间验证配置
        $(function(){
            var json = eval({$sublist});
            var kz_json = eval({$kz_info});  //扩展配置数据
            var menu = '{$menu}';
            var uuid = '{$uuid}';  //员工编码
            var data = {
                name:menu,
                action:'__MODULE__/Info/addok',
                method:'post',
                json:json,
                dic:dic,
                layer_js: layer_js,
                kz_json:kz_json
            };
            addNew(data);
            //检测表单提交数据合法性
            $('.btn-default').click(function(){
                //检测附件的大小和类型
                var tob = 0;
                $('.file_input').each(function(){
                    var fjresolt = fileFJSize($(this)[0]);
                    if(!fjresolt){
                        tob++;
                    }
                });
                if(tob){
                    return false;
                }
                //验证时间规则
                for(var i in sj_info){
                    var bj_val = $('input[name='+i+']').val();
                    var bj_name = $('input[name='+i+']').parent().parent().parent().find('label').text();
                    if(bj_name.indexOf('*')>-1){
                        bj_name = bj_name.substr(0, bj_name.length - 1);
                    }
                    var b_bj_val = $('input[name='+sj_info[i].max+']').val();
                    var b_bj_name = $('input[name='+sj_info[i].max+']').parent().parent().parent().find('label').text();
                    if(b_bj_name.indexOf('*')>-1){
                        b_bj_name = b_bj_name.substr(0, b_bj_name.length - 1);
                    }

                    if(sj_info[i].method == 1){
                        if(bj_val && b_bj_val && bj_val <= b_bj_val){
                            layer.alert(bj_name+' 不能小于或等于 '+b_bj_name);
                            return false;
                        }
                    }else if(sj_info[i].method == 2){
                        if(bj_val && b_bj_val && bj_val < b_bj_val){
                            layer.alert(bj_name+' 不能小于 '+b_bj_name);
                            return false;
                        }
                    }
                }
            });

            //唯一性验证
            $('.checkWyx').change(function () {
                var self = $(this);
                var val = $(this).val();
                var zd_name = $(this).attr('name');
                var form = $(this).parents('form');
                if (val == '是') {
                    var caption = $(this).parent().parent().parent().find('label').text();
                    caption = caption.substr(0, caption.length - 1);
                    var data = {uuid: uuid, item: menu, name: zd_name};
                    var resolot = aa(data);
                    if (resolot.type == 2) {
                        var text = '字段 ' + caption + ' 已经存在唯一值,您是保留当前值,更改其他该字段的值,还是更改当前字段的值该为否,其他记录值不变?';
                        layer.confirm(text, {
                            btn: ['保留', '不保留'] //按钮
                        }, function () {
                            var zj_input = '<input type="hidden" name="upd-' + zd_name + '" value="'+resolot.key+'">';
                            form.append(zj_input);
                            layer.msg(caption + '的值为是,将更改其他记录值!');
                        }, function () {
                            self.val('否');
                            layer.msg(caption + '的值改为否,其他记录此字段值不变!');
                        });
                    }
                }

            });
            function aa(data) {
                var resolt = null;
                $.ajax({
                    url: '__MODULE__/Info/checkWyx',
                    type: 'post',
                    data: data,
                    async: false,
                    success: function (e) {
                        resolt = e;
                    }
                });
                return resolt;
            }
            //点击取消按钮隐藏alert提示
            $('#dialog2_but').bind('click',function(){
                $('#dialog2').hide();
            });

            //时间日期插件
            $('.date').each(function(){
                $(this).ionDatePicker({
                    lang: 'zh-cn',
                    format: 'YYYY-MM-DD'
                });
            });

            //初始化树形结
            for(var i in layer_id){
                $("#"+i).on("click",{i: i},function (e) {
                    var q=0;
                    $.fn.zTree.init($("#tree"), setting,layer_js[layer_id[e.data.i]]);
                    showMenu($(this));
                });
            }
            //重新调整树形结构宽度
            $(window).resize(function () {
                $("#menuContent").hide();
                $("#menuContent ul").width($("#inputText_0").parent('div').width()+"px");
            });
            $("#menuContent ul").width($("#inputText_0").parent('div').width()+"px");
        });
        // 附件上传
        function add_file(e){
            var pNode=$(e).parents('.file_warp');
            pNode.parent('div').append(pNode.clone().children('input').val('').end()).children('.file_warp').eq(0).siblings().find('.file_add').attr("class",'file_remove').find('a').attr("onclick",'remove_file(this)').html("[-]");
        }
        function remove_file(e) {
            $(e).parents('.file_warp').remove();
        }
        function  remove_result(e) {
            $(e).parents('.file_info').remove();
        }
        //检测附件
        function fileFJSize(obj,tob){
            if(!obj.value){
                return true;
            }
            var photoExt = obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();//获得文件后缀名
            var filetype = '.jpg,.gif,.png,.jpeg,.xls,.xlsx,.doc,.docx,.ppt,.pptx';
            //alert(filetype.indexOf(photoExt));return false;
            if(filetype.indexOf(photoExt)<0){
                tob++;
                layer.alert("上传的只支持'jpg', 'gif', 'png', 'jpeg','xls','xlsx','doc','docx','ppt','pptx'的格式!");
                return false;
            }
            var fileSize = 0;
            var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
            if (isIE && !obj.files) {
                var filePath = obj.value;
                var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
                var file = fileSystem.GetFile (filePath);
                fileSize = file.Size;
            }else {
                fileSize = obj.files[0].size;
            }
            fileSize=Math.round(fileSize/1024*100)/100; //单位为KB
            if(fileSize >= 2000){
                tob++;
                layer.alert("上传的附件大小超过2M，请重新上传!");
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
    <script src="__PUBLIC__/User/newjs/ion.calendar.js"></script>
    <div>
        <div class="content_wrap">
        </div>
        <div id="menuContent" class="menuContent" style=" display:none;position: absolute;">
            <ul id="tree" class="ztree" style="margin-top:0; width:370px; height: 300px;"></ul>
        </div>
    </div>
    <div id="dialog2" style="display:none;">
        <div class="weui-mask"></div>
        <div class="weui-dialog">
            <div class="weui-dialog__hd"><strong class="weui-dialog__title">操作提示</strong></div>
            <div class="weui-dialog__bd" id="dialog2_msg">
            </div>
            <div class="weui-dialog__ft">
                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary" id="dialog2_but">好的</a>
            </div>
        </div>
    </div>

    <script src="__PUBLIC__/User/newjs/custom.js" type="text/javascript"></script>
</body>
</html>